{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 第二章习题\n",
    "\n",
    "### 一、填空题\n",
    "\n",
    "1.列表的`sort()`方法没有返回值,或者说返回值为________."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "空值None"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2.已知列表 `data=[1,2,30 4]`，那么`data[2:100]`的值为________."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "[30,4]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.己知`x=3`和`y=5`,那么执行语句`x,y=y,x`之后，`y`的值为________."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4．已知字典 `data= {'a;97, 'A' :65}`,那么`data.get('a', None)`的值为________."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "97"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 二、判断题\n",
    "\n",
    "1.生成器表达式的计算结果是一个元组。`(    )`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "false"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2.包含列表的元组可以作为字典的“键”。(  | ) "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "false"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.包含列表的元组不可以作为集合的元素。(   )"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "true"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4．列表的`rindex()`方法返回指定元素在列表中最后一次出现的位置。`(    )`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "false"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 三、编程题\n",
    "\n",
    "1.输入一个字符串，输出其中每个字符的出现次数。要求使用标准库`collotections`中的`Counter`类,请自行查阅相关用法。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个字符串：'1,2,3,4,5,2,1'\n"
     ]
    }
   ],
   "source": [
    "from collections import Counter\n",
    "text = input('请输入一个字符串：')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "X = Counter(text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Counter({',': 6, \"'\": 2, '1': 2, '2': 2, '3': 1, '4': 1, '5': 1})\n"
     ]
    }
   ],
   "source": [
    "print(X)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2．输入一个字符串,输出其中只出现了一次的字符及其下标。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个字符串：'1,4,5,5,1'\n"
     ]
    }
   ],
   "source": [
    "C = input('请输入一个字符串：')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "D = [(ch,index) for index,ch in enumerate(text) if text.index(ch)==text.rindex(ch)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[('3', 5), ('4', 7), ('5', 9)]\n"
     ]
    }
   ],
   "source": [
    "print(D)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3．输入一个字符串,输出其中每个唯一字符最后一次出现的下标。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个字符串'1,8,8,9,4,5,0,4'\n"
     ]
    }
   ],
   "source": [
    "s = eval(input('请输入一个字符串'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[('1', 0), ('8', 4), ('9', 6), ('5', 10), ('0', 12), (',', 13), ('4', 14)]\n"
     ]
    }
   ],
   "source": [
    "positions =[(ch,index) for index,ch in enumerate(s)\n",
    "if index == s.rindex(ch)]\n",
    "print(positions)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4．输入包含若干集合的列表，输出这些集合的并集。提示:使用`reduce()`函数和`operator`模块中的运算实现多个集合的并集。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入包含若干集合的列表：[{14,55},{145,556}]\n"
     ]
    }
   ],
   "source": [
    "from functools import reduce\n",
    "a =eval(input(\"请输入包含若干集合的列表：\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{145, 556, 14, 55}\n"
     ]
    }
   ],
   "source": [
    "from operator import __or__\n",
    "print(reduce(__or__,a))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "5．输入一个字符串,检查该字符串是否为回文（正着读和反看读都一样的字符串)，如果是就输出`Yes`，否则输出`No`。要求使用切片实现"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个字符串'1,5,4,6,9,8'\n"
     ]
    }
   ],
   "source": [
    "str1 = input('请输入一个字符串')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "No\n"
     ]
    }
   ],
   "source": [
    "str2 = str1[::-1]\n",
    "if str1 == str2:\n",
    "    print('Yes')\n",
    "else:\n",
    "    print('No')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 课本上65页课后习题"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1.可迭代对象"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2.4"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.None"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4.remove()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "5.[6,7,9,11]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "6.() 键 值 键"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "7.items() key() values()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "8.['dict(zip(a,b))']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "9.b=a[::3]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "10.5 for i in range(10)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "11.不可以"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "12."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['fagbc']\n"
     ]
    }
   ],
   "source": [
    "data = ['fagbc','aaccbbdd','yjyjyj,koukou']\n",
    "print(list(filter(lambda s:len(set(s))/len(s) >0.5,data)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "13."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]\n"
     ]
    }
   ],
   "source": [
    "def prime(x):                       \n",
    "    for i in range(2,x):\n",
    "        if x%i==0:\n",
    "            return False\n",
    "        if i==x-1:\n",
    "            return True\n",
    "output=filter(prime,range(2,1001))\n",
    "print(list(output))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "15."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[67, 75, 99, 46, 75, 92, 31, 60, 52, 73, 48, 65, 87, 48, 51, 54, 8, 90, 83, 85, 28, 47, 4, 80, 34, 49, 43, 87, 20, 100, 8, 55, 76, 61, 11, 40, 86, 64, 86, 16, 50, 44, 29, 22, 83, 18, 36, 55, 39, 59, 48, 40, 45, 21, 95, 21, 52, 16, 66, 68, 43, 93, 70, 23, 64, 48, 11, 54, 54, 58, 68, 88, 29, 74, 31, 17, 61, 61, 46, 29, 15, 51, 58, 56, 10, 31, 45, 34, 79, 1, 4, 65, 44, 3, 27, 56, 0, 4, 47, 74, 23, 37, 61, 1, 60, 42, 74, 98, 37, 48, 58, 56, 23, 73, 16, 4, 82, 17, 29, 68, 28, 61, 59, 98, 13, 68, 98, 57, 93, 36, 99, 23, 62, 62, 87, 37, 53, 26, 12, 40, 9, 34, 43, 70, 98, 25, 74, 47, 51, 31, 45, 5, 5, 2, 33, 70, 45, 85, 89, 55, 80, 3, 32, 98, 91, 33, 7, 59, 35, 39, 49, 15, 59, 30, 27, 87, 69, 74, 95, 34, 6, 9, 50, 43, 77, 19, 22, 23, 87, 81, 41, 58, 76, 47, 10, 88, 5, 83, 80, 73, 91, 67, 82, 84, 93, 75, 28, 99, 2, 30, 38, 21, 39, 9, 27, 27, 59, 66, 96, 58, 2, 30, 79, 8, 89, 75, 15, 32, 72, 21, 94, 62, 8, 86, 51, 96, 28, 70, 40, 71, 37, 91, 38, 96, 82, 43, 0, 51, 61, 90, 63, 13, 49, 97, 54, 51, 18, 18, 97, 43, 100, 99, 12, 15, 55, 65, 41, 51, 46, 33, 46, 100, 72, 69, 19, 20, 74, 34, 41, 19, 70, 78, 75, 5, 74, 30, 42, 13, 56, 19, 68, 51, 31, 64, 61, 51, 60, 40, 1, 87, 38, 39, 36, 48, 34, 17, 46, 97, 44, 98, 40, 96, 35, 92, 55, 64, 45, 53, 75, 38, 72, 81, 86, 54, 19, 54, 84, 69, 76, 45, 84, 3, 87, 97, 53, 18, 58, 36, 33, 12, 80, 36, 73, 12, 47, 15, 20, 49, 88, 15, 76, 79, 100, 19, 24, 25, 92, 57, 19, 41, 62, 89, 0, 77, 51, 47, 33, 43, 60, 31, 100, 23, 37, 94, 77, 66, 53, 37, 19, 24, 17, 65, 43, 28, 90, 64, 25, 35, 44, 99, 18, 36, 39, 23, 64, 28, 46, 98, 10, 83, 95, 75, 95, 85, 20, 1, 37, 9, 46, 44, 97, 96, 53, 41, 52, 93, 86, 0, 49, 4, 4, 22, 69, 15, 93, 44, 60, 44, 31, 50, 56, 20, 86, 60, 4, 43, 43, 6, 5, 99, 99, 80, 9, 92, 30, 3, 53, 13, 78, 34, 45, 17, 8, 23, 85, 94, 47, 75, 41, 70, 43, 59, 83, 3, 72, 87, 90, 50, 3, 33, 76, 61, 98, 40, 93, 69, 61, 38, 89, 40, 36, 62, 96, 83, 87, 39, 45, 82, 3, 76, 53, 67, 71, 52, 26, 91, 21, 58, 84, 64, 51, 90, 27, 14, 23, 40, 80, 18, 80, 32, 19, 91, 24, 64, 52, 76, 34, 43, 46, 93, 14, 97, 46, 22, 51, 41, 97, 27, 4, 58, 39, 84, 98, 36, 82, 86, 3, 60, 87, 50, 100, 29, 82, 55, 84, 26, 1, 87, 38, 92, 6, 82, 86, 45, 27, 81, 33, 19, 4, 77, 85, 0, 83, 76, 100, 20, 91, 12, 87, 33, 67, 73, 48, 44, 89, 56, 43, 68, 9, 0, 21, 38, 16, 87, 74, 58, 81, 45, 60, 8, 84, 85, 52, 97, 16, 71, 53, 93, 3, 85, 43, 92, 96, 6, 100, 19, 82, 98, 35, 22, 18, 30, 81, 53, 49, 22, 99, 19, 34, 71, 33, 21, 83, 55, 75, 4, 78, 49, 64, 10, 24, 30, 92, 87, 75, 69, 96, 72, 95, 14, 62, 44, 44, 84, 3, 94, 32, 12, 59, 13, 33, 38, 52, 4, 78, 41, 54, 69, 40, 12, 98, 55, 99, 69, 6, 18, 45, 20, 9, 31, 1, 20, 50, 51, 49, 16, 52, 26, 39, 76, 46, 81, 48, 100, 56, 61, 50, 87, 58, 30, 21, 84, 70, 56, 90, 49, 86, 18, 10, 37, 7, 55, 98, 20, 86, 4, 41, 43, 29, 42, 35, 95, 3, 40, 100, 32, 90, 89, 49, 13, 21, 7, 23, 36, 46, 100, 19, 16, 61, 35, 53, 27, 99, 17, 52, 83, 56, 47, 51, 40, 68, 37, 95, 59, 97, 43, 15, 61, 59, 86, 18, 19, 98, 80, 89, 17, 99, 53, 58, 10, 30, 70, 69, 23, 98, 20, 41, 49, 24, 62, 9, 19, 62, 9, 6, 40, 3, 36, 11, 64, 10, 0, 78, 20, 26, 59, 39, 26, 64, 69, 32, 30, 4, 21, 60, 70, 7, 85, 9, 44, 8, 37, 38, 50, 80, 45, 94, 77, 69, 41, 96, 8, 45, 14, 75, 9, 17, 7, 2, 60, 30, 86, 29, 4, 46, 84, 70, 59, 76, 80, 21, 73, 83, 38, 80, 28, 3, 81, 77, 59, 29, 19, 20, 47, 45, 53, 76, 76, 29, 40, 80, 76, 14, 7, 27, 89, 75, 88, 40, 0, 11, 41, 28, 67, 72, 69, 7, 72, 67, 92, 29, 31, 15, 17, 88, 78, 88, 52, 93, 4, 95, 52, 97, 63, 2, 28, 80, 89, 9, 60, 58, 42, 3, 82, 33, 77, 33, 53, 23, 96, 92, 13, 50, 68, 30, 1, 63, 99, 97, 65, 83, 82, 9, 84, 52, 96, 93, 58, 37, 65, 75, 81, 21, 57, 36, 70, 78, 62, 91, 43, 55, 33, 18, 13, 49, 22, 62, 33, 64, 65, 57, 47, 74, 34, 77, 81, 36, 59, 45, 68, 84, 47, 88, 99, 100, 59, 18, 32, 28, 80, 85, 61, 6, 52, 34, 69, 41, 39, 59, 87, 100, 18, 50, 32, 48, 82, 28, 81, 70, 11, 38, 36, 10, 16, 83, 55, 95, 30, 4, 20, 87, 40, 47, 27, 73, 42, 81, 16, 78, 100]\n",
      "67 : 6\n",
      "75 : 13\n",
      "99 : 13\n",
      "46 : 12\n",
      "75 : 13\n",
      "92 : 9\n",
      "31 : 9\n",
      "60 : 11\n",
      "52 : 13\n",
      "73 : 7\n",
      "48 : 9\n",
      "65 : 7\n",
      "87 : 17\n",
      "48 : 9\n",
      "51 : 14\n",
      "54 : 7\n",
      "8 : 8\n",
      "90 : 7\n",
      "83 : 12\n",
      "85 : 9\n",
      "28 : 11\n",
      "47 : 12\n",
      "4 : 16\n",
      "80 : 14\n",
      "34 : 11\n",
      "49 : 12\n",
      "43 : 17\n",
      "87 : 17\n",
      "20 : 13\n",
      "100 : 14\n",
      "8 : 8\n",
      "55 : 11\n",
      "76 : 13\n",
      "61 : 13\n",
      "11 : 5\n",
      "40 : 16\n",
      "86 : 12\n",
      "64 : 12\n",
      "86 : 12\n",
      "16 : 9\n",
      "50 : 10\n",
      "44 : 11\n",
      "29 : 10\n",
      "22 : 7\n",
      "83 : 12\n",
      "18 : 13\n",
      "36 : 13\n",
      "55 : 11\n",
      "39 : 10\n",
      "59 : 15\n",
      "48 : 9\n",
      "40 : 16\n",
      "45 : 15\n",
      "21 : 12\n",
      "95 : 9\n",
      "21 : 12\n",
      "52 : 13\n",
      "16 : 9\n",
      "66 : 3\n",
      "68 : 9\n",
      "43 : 17\n",
      "93 : 10\n",
      "70 : 12\n",
      "23 : 12\n",
      "64 : 12\n",
      "48 : 9\n",
      "11 : 5\n",
      "54 : 7\n",
      "54 : 7\n",
      "58 : 13\n",
      "68 : 9\n",
      "88 : 7\n",
      "29 : 10\n",
      "74 : 9\n",
      "31 : 9\n",
      "17 : 9\n",
      "61 : 13\n",
      "61 : 13\n",
      "46 : 12\n",
      "29 : 10\n",
      "15 : 9\n",
      "51 : 14\n",
      "58 : 13\n",
      "56 : 9\n",
      "10 : 8\n",
      "31 : 9\n",
      "45 : 15\n",
      "34 : 11\n",
      "79 : 3\n",
      "1 : 7\n",
      "4 : 16\n",
      "65 : 7\n",
      "44 : 11\n",
      "3 : 14\n",
      "27 : 10\n",
      "56 : 9\n",
      "0 : 8\n",
      "4 : 16\n",
      "47 : 12\n",
      "74 : 9\n",
      "23 : 12\n",
      "37 : 11\n",
      "61 : 13\n",
      "1 : 7\n",
      "60 : 11\n",
      "42 : 5\n",
      "74 : 9\n",
      "98 : 14\n",
      "37 : 11\n",
      "48 : 9\n",
      "58 : 13\n",
      "56 : 9\n",
      "23 : 12\n",
      "73 : 7\n",
      "16 : 9\n",
      "4 : 16\n",
      "82 : 11\n",
      "17 : 9\n",
      "29 : 10\n",
      "68 : 9\n",
      "28 : 11\n",
      "61 : 13\n",
      "59 : 15\n",
      "98 : 14\n",
      "13 : 8\n",
      "68 : 9\n",
      "98 : 14\n",
      "57 : 4\n",
      "93 : 10\n",
      "36 : 13\n",
      "99 : 13\n",
      "23 : 12\n",
      "62 : 10\n",
      "62 : 10\n",
      "87 : 17\n",
      "37 : 11\n",
      "53 : 13\n",
      "26 : 6\n",
      "12 : 7\n",
      "40 : 16\n",
      "9 : 13\n",
      "34 : 11\n",
      "43 : 17\n",
      "70 : 12\n",
      "98 : 14\n",
      "25 : 3\n",
      "74 : 9\n",
      "47 : 12\n",
      "51 : 14\n",
      "31 : 9\n",
      "45 : 15\n",
      "5 : 5\n",
      "5 : 5\n",
      "2 : 5\n",
      "33 : 14\n",
      "70 : 12\n",
      "45 : 15\n",
      "85 : 9\n",
      "89 : 9\n",
      "55 : 11\n",
      "80 : 14\n",
      "3 : 14\n",
      "32 : 8\n",
      "98 : 14\n",
      "91 : 7\n",
      "33 : 14\n",
      "7 : 7\n",
      "59 : 15\n",
      "35 : 6\n",
      "39 : 10\n",
      "49 : 12\n",
      "15 : 9\n",
      "59 : 15\n",
      "30 : 13\n",
      "27 : 10\n",
      "87 : 17\n",
      "69 : 13\n",
      "74 : 9\n",
      "95 : 9\n",
      "34 : 11\n",
      "6 : 7\n",
      "9 : 13\n",
      "50 : 10\n",
      "43 : 17\n",
      "77 : 8\n",
      "19 : 16\n",
      "22 : 7\n",
      "23 : 12\n",
      "87 : 17\n",
      "81 : 11\n",
      "41 : 13\n",
      "58 : 13\n",
      "76 : 13\n",
      "47 : 12\n",
      "10 : 8\n",
      "88 : 7\n",
      "5 : 5\n",
      "83 : 12\n",
      "80 : 14\n",
      "73 : 7\n",
      "91 : 7\n",
      "67 : 6\n",
      "82 : 11\n",
      "84 : 12\n",
      "93 : 10\n",
      "75 : 13\n",
      "28 : 11\n",
      "99 : 13\n",
      "2 : 5\n",
      "30 : 13\n",
      "38 : 11\n",
      "21 : 12\n",
      "39 : 10\n",
      "9 : 13\n",
      "27 : 10\n",
      "27 : 10\n",
      "59 : 15\n",
      "66 : 3\n",
      "96 : 11\n",
      "58 : 13\n",
      "2 : 5\n",
      "30 : 13\n",
      "79 : 3\n",
      "8 : 8\n",
      "89 : 9\n",
      "75 : 13\n",
      "15 : 9\n",
      "32 : 8\n",
      "72 : 7\n",
      "21 : 12\n",
      "94 : 5\n",
      "62 : 10\n",
      "8 : 8\n",
      "86 : 12\n",
      "51 : 14\n",
      "96 : 11\n",
      "28 : 11\n",
      "70 : 12\n",
      "40 : 16\n",
      "71 : 4\n",
      "37 : 11\n",
      "91 : 7\n",
      "38 : 11\n",
      "96 : 11\n",
      "82 : 11\n",
      "43 : 17\n",
      "0 : 8\n",
      "51 : 14\n",
      "61 : 13\n",
      "90 : 7\n",
      "63 : 3\n",
      "13 : 8\n",
      "49 : 12\n",
      "97 : 11\n",
      "54 : 7\n",
      "51 : 14\n",
      "18 : 13\n",
      "18 : 13\n",
      "97 : 11\n",
      "43 : 17\n",
      "100 : 14\n",
      "99 : 13\n",
      "12 : 7\n",
      "15 : 9\n",
      "55 : 11\n",
      "65 : 7\n",
      "41 : 13\n",
      "51 : 14\n",
      "46 : 12\n",
      "33 : 14\n",
      "46 : 12\n",
      "100 : 14\n",
      "72 : 7\n",
      "69 : 13\n",
      "19 : 16\n",
      "20 : 13\n",
      "74 : 9\n",
      "34 : 11\n",
      "41 : 13\n",
      "19 : 16\n",
      "70 : 12\n",
      "78 : 8\n",
      "75 : 13\n",
      "5 : 5\n",
      "74 : 9\n",
      "30 : 13\n",
      "42 : 5\n",
      "13 : 8\n",
      "56 : 9\n",
      "19 : 16\n",
      "68 : 9\n",
      "51 : 14\n",
      "31 : 9\n",
      "64 : 12\n",
      "61 : 13\n",
      "51 : 14\n",
      "60 : 11\n",
      "40 : 16\n",
      "1 : 7\n",
      "87 : 17\n",
      "38 : 11\n",
      "39 : 10\n",
      "36 : 13\n",
      "48 : 9\n",
      "34 : 11\n",
      "17 : 9\n",
      "46 : 12\n",
      "97 : 11\n",
      "44 : 11\n",
      "98 : 14\n",
      "40 : 16\n",
      "96 : 11\n",
      "35 : 6\n",
      "92 : 9\n",
      "55 : 11\n",
      "64 : 12\n",
      "45 : 15\n",
      "53 : 13\n",
      "75 : 13\n",
      "38 : 11\n",
      "72 : 7\n",
      "81 : 11\n",
      "86 : 12\n",
      "54 : 7\n",
      "19 : 16\n",
      "54 : 7\n",
      "84 : 12\n",
      "69 : 13\n",
      "76 : 13\n",
      "45 : 15\n",
      "84 : 12\n",
      "3 : 14\n",
      "87 : 17\n",
      "97 : 11\n",
      "53 : 13\n",
      "18 : 13\n",
      "58 : 13\n",
      "36 : 13\n",
      "33 : 14\n",
      "12 : 7\n",
      "80 : 14\n",
      "36 : 13\n",
      "73 : 7\n",
      "12 : 7\n",
      "47 : 12\n",
      "15 : 9\n",
      "20 : 13\n",
      "49 : 12\n",
      "88 : 7\n",
      "15 : 9\n",
      "76 : 13\n",
      "79 : 3\n",
      "100 : 14\n",
      "19 : 16\n",
      "24 : 5\n",
      "25 : 3\n",
      "92 : 9\n",
      "57 : 4\n",
      "19 : 16\n",
      "41 : 13\n",
      "62 : 10\n",
      "89 : 9\n",
      "0 : 8\n",
      "77 : 8\n",
      "51 : 14\n",
      "47 : 12\n",
      "33 : 14\n",
      "43 : 17\n",
      "60 : 11\n",
      "31 : 9\n",
      "100 : 14\n",
      "23 : 12\n",
      "37 : 11\n",
      "94 : 5\n",
      "77 : 8\n",
      "66 : 3\n",
      "53 : 13\n",
      "37 : 11\n",
      "19 : 16\n",
      "24 : 5\n",
      "17 : 9\n",
      "65 : 7\n",
      "43 : 17\n",
      "28 : 11\n",
      "90 : 7\n",
      "64 : 12\n",
      "25 : 3\n",
      "35 : 6\n",
      "44 : 11\n",
      "99 : 13\n",
      "18 : 13\n",
      "36 : 13\n",
      "39 : 10\n",
      "23 : 12\n",
      "64 : 12\n",
      "28 : 11\n",
      "46 : 12\n",
      "98 : 14\n",
      "10 : 8\n",
      "83 : 12\n",
      "95 : 9\n",
      "75 : 13\n",
      "95 : 9\n",
      "85 : 9\n",
      "20 : 13\n",
      "1 : 7\n",
      "37 : 11\n",
      "9 : 13\n",
      "46 : 12\n",
      "44 : 11\n",
      "97 : 11\n",
      "96 : 11\n",
      "53 : 13\n",
      "41 : 13\n",
      "52 : 13\n",
      "93 : 10\n",
      "86 : 12\n",
      "0 : 8\n",
      "49 : 12\n",
      "4 : 16\n",
      "4 : 16\n",
      "22 : 7\n",
      "69 : 13\n",
      "15 : 9\n",
      "93 : 10\n",
      "44 : 11\n",
      "60 : 11\n",
      "44 : 11\n",
      "31 : 9\n",
      "50 : 10\n",
      "56 : 9\n",
      "20 : 13\n",
      "86 : 12\n",
      "60 : 11\n",
      "4 : 16\n",
      "43 : 17\n",
      "43 : 17\n",
      "6 : 7\n",
      "5 : 5\n",
      "99 : 13\n",
      "99 : 13\n",
      "80 : 14\n",
      "9 : 13\n",
      "92 : 9\n",
      "30 : 13\n",
      "3 : 14\n",
      "53 : 13\n",
      "13 : 8\n",
      "78 : 8\n",
      "34 : 11\n",
      "45 : 15\n",
      "17 : 9\n",
      "8 : 8\n",
      "23 : 12\n",
      "85 : 9\n",
      "94 : 5\n",
      "47 : 12\n",
      "75 : 13\n",
      "41 : 13\n",
      "70 : 12\n",
      "43 : 17\n",
      "59 : 15\n",
      "83 : 12\n",
      "3 : 14\n",
      "72 : 7\n",
      "87 : 17\n",
      "90 : 7\n",
      "50 : 10\n",
      "3 : 14\n",
      "33 : 14\n",
      "76 : 13\n",
      "61 : 13\n",
      "98 : 14\n",
      "40 : 16\n",
      "93 : 10\n",
      "69 : 13\n",
      "61 : 13\n",
      "38 : 11\n",
      "89 : 9\n",
      "40 : 16\n",
      "36 : 13\n",
      "62 : 10\n",
      "96 : 11\n",
      "83 : 12\n",
      "87 : 17\n",
      "39 : 10\n",
      "45 : 15\n",
      "82 : 11\n",
      "3 : 14\n",
      "76 : 13\n",
      "53 : 13\n",
      "67 : 6\n",
      "71 : 4\n",
      "52 : 13\n",
      "26 : 6\n",
      "91 : 7\n",
      "21 : 12\n",
      "58 : 13\n",
      "84 : 12\n",
      "64 : 12\n",
      "51 : 14\n",
      "90 : 7\n",
      "27 : 10\n",
      "14 : 5\n",
      "23 : 12\n",
      "40 : 16\n",
      "80 : 14\n",
      "18 : 13\n",
      "80 : 14\n",
      "32 : 8\n",
      "19 : 16\n",
      "91 : 7\n",
      "24 : 5\n",
      "64 : 12\n",
      "52 : 13\n",
      "76 : 13\n",
      "34 : 11\n",
      "43 : 17\n",
      "46 : 12\n",
      "93 : 10\n",
      "14 : 5\n",
      "97 : 11\n",
      "46 : 12\n",
      "22 : 7\n",
      "51 : 14\n",
      "41 : 13\n",
      "97 : 11\n",
      "27 : 10\n",
      "4 : 16\n",
      "58 : 13\n",
      "39 : 10\n",
      "84 : 12\n",
      "98 : 14\n",
      "36 : 13\n",
      "82 : 11\n",
      "86 : 12\n",
      "3 : 14\n",
      "60 : 11\n",
      "87 : 17\n",
      "50 : 10\n",
      "100 : 14\n",
      "29 : 10\n",
      "82 : 11\n",
      "55 : 11\n",
      "84 : 12\n",
      "26 : 6\n",
      "1 : 7\n",
      "87 : 17\n",
      "38 : 11\n",
      "92 : 9\n",
      "6 : 7\n",
      "82 : 11\n",
      "86 : 12\n",
      "45 : 15\n",
      "27 : 10\n",
      "81 : 11\n",
      "33 : 14\n",
      "19 : 16\n",
      "4 : 16\n",
      "77 : 8\n",
      "85 : 9\n",
      "0 : 8\n",
      "83 : 12\n",
      "76 : 13\n",
      "100 : 14\n",
      "20 : 13\n",
      "91 : 7\n",
      "12 : 7\n",
      "87 : 17\n",
      "33 : 14\n",
      "67 : 6\n",
      "73 : 7\n",
      "48 : 9\n",
      "44 : 11\n",
      "89 : 9\n",
      "56 : 9\n",
      "43 : 17\n",
      "68 : 9\n",
      "9 : 13\n",
      "0 : 8\n",
      "21 : 12\n",
      "38 : 11\n",
      "16 : 9\n",
      "87 : 17\n",
      "74 : 9\n",
      "58 : 13\n",
      "81 : 11\n",
      "45 : 15\n",
      "60 : 11\n",
      "8 : 8\n",
      "84 : 12\n",
      "85 : 9\n",
      "52 : 13\n",
      "97 : 11\n",
      "16 : 9\n",
      "71 : 4\n",
      "53 : 13\n",
      "93 : 10\n",
      "3 : 14\n",
      "85 : 9\n",
      "43 : 17\n",
      "92 : 9\n",
      "96 : 11\n",
      "6 : 7\n",
      "100 : 14\n",
      "19 : 16\n",
      "82 : 11\n",
      "98 : 14\n",
      "35 : 6\n",
      "22 : 7\n",
      "18 : 13\n",
      "30 : 13\n",
      "81 : 11\n",
      "53 : 13\n",
      "49 : 12\n",
      "22 : 7\n",
      "99 : 13\n",
      "19 : 16\n",
      "34 : 11\n",
      "71 : 4\n",
      "33 : 14\n",
      "21 : 12\n",
      "83 : 12\n",
      "55 : 11\n",
      "75 : 13\n",
      "4 : 16\n",
      "78 : 8\n",
      "49 : 12\n",
      "64 : 12\n",
      "10 : 8\n",
      "24 : 5\n",
      "30 : 13\n",
      "92 : 9\n",
      "87 : 17\n",
      "75 : 13\n",
      "69 : 13\n",
      "96 : 11\n",
      "72 : 7\n",
      "95 : 9\n",
      "14 : 5\n",
      "62 : 10\n",
      "44 : 11\n",
      "44 : 11\n",
      "84 : 12\n",
      "3 : 14\n",
      "94 : 5\n",
      "32 : 8\n",
      "12 : 7\n",
      "59 : 15\n",
      "13 : 8\n",
      "33 : 14\n",
      "38 : 11\n",
      "52 : 13\n",
      "4 : 16\n",
      "78 : 8\n",
      "41 : 13\n",
      "54 : 7\n",
      "69 : 13\n",
      "40 : 16\n",
      "12 : 7\n",
      "98 : 14\n",
      "55 : 11\n",
      "99 : 13\n",
      "69 : 13\n",
      "6 : 7\n",
      "18 : 13\n",
      "45 : 15\n",
      "20 : 13\n",
      "9 : 13\n",
      "31 : 9\n",
      "1 : 7\n",
      "20 : 13\n",
      "50 : 10\n",
      "51 : 14\n",
      "49 : 12\n",
      "16 : 9\n",
      "52 : 13\n",
      "26 : 6\n",
      "39 : 10\n",
      "76 : 13\n",
      "46 : 12\n",
      "81 : 11\n",
      "48 : 9\n",
      "100 : 14\n",
      "56 : 9\n",
      "61 : 13\n",
      "50 : 10\n",
      "87 : 17\n",
      "58 : 13\n",
      "30 : 13\n",
      "21 : 12\n",
      "84 : 12\n",
      "70 : 12\n",
      "56 : 9\n",
      "90 : 7\n",
      "49 : 12\n",
      "86 : 12\n",
      "18 : 13\n",
      "10 : 8\n",
      "37 : 11\n",
      "7 : 7\n",
      "55 : 11\n",
      "98 : 14\n",
      "20 : 13\n",
      "86 : 12\n",
      "4 : 16\n",
      "41 : 13\n",
      "43 : 17\n",
      "29 : 10\n",
      "42 : 5\n",
      "35 : 6\n",
      "95 : 9\n",
      "3 : 14\n",
      "40 : 16\n",
      "100 : 14\n",
      "32 : 8\n",
      "90 : 7\n",
      "89 : 9\n",
      "49 : 12\n",
      "13 : 8\n",
      "21 : 12\n",
      "7 : 7\n",
      "23 : 12\n",
      "36 : 13\n",
      "46 : 12\n",
      "100 : 14\n",
      "19 : 16\n",
      "16 : 9\n",
      "61 : 13\n",
      "35 : 6\n",
      "53 : 13\n",
      "27 : 10\n",
      "99 : 13\n",
      "17 : 9\n",
      "52 : 13\n",
      "83 : 12\n",
      "56 : 9\n",
      "47 : 12\n",
      "51 : 14\n",
      "40 : 16\n",
      "68 : 9\n",
      "37 : 11\n",
      "95 : 9\n",
      "59 : 15\n",
      "97 : 11\n",
      "43 : 17\n",
      "15 : 9\n",
      "61 : 13\n",
      "59 : 15\n",
      "86 : 12\n",
      "18 : 13\n",
      "19 : 16\n",
      "98 : 14\n",
      "80 : 14\n",
      "89 : 9\n",
      "17 : 9\n",
      "99 : 13\n",
      "53 : 13\n",
      "58 : 13\n",
      "10 : 8\n",
      "30 : 13\n",
      "70 : 12\n",
      "69 : 13\n",
      "23 : 12\n",
      "98 : 14\n",
      "20 : 13\n",
      "41 : 13\n",
      "49 : 12\n",
      "24 : 5\n",
      "62 : 10\n",
      "9 : 13\n",
      "19 : 16\n",
      "62 : 10\n",
      "9 : 13\n",
      "6 : 7\n",
      "40 : 16\n",
      "3 : 14\n",
      "36 : 13\n",
      "11 : 5\n",
      "64 : 12\n",
      "10 : 8\n",
      "0 : 8\n",
      "78 : 8\n",
      "20 : 13\n",
      "26 : 6\n",
      "59 : 15\n",
      "39 : 10\n",
      "26 : 6\n",
      "64 : 12\n",
      "69 : 13\n",
      "32 : 8\n",
      "30 : 13\n",
      "4 : 16\n",
      "21 : 12\n",
      "60 : 11\n",
      "70 : 12\n",
      "7 : 7\n",
      "85 : 9\n",
      "9 : 13\n",
      "44 : 11\n",
      "8 : 8\n",
      "37 : 11\n",
      "38 : 11\n",
      "50 : 10\n",
      "80 : 14\n",
      "45 : 15\n",
      "94 : 5\n",
      "77 : 8\n",
      "69 : 13\n",
      "41 : 13\n",
      "96 : 11\n",
      "8 : 8\n",
      "45 : 15\n",
      "14 : 5\n",
      "75 : 13\n",
      "9 : 13\n",
      "17 : 9\n",
      "7 : 7\n",
      "2 : 5\n",
      "60 : 11\n",
      "30 : 13\n",
      "86 : 12\n",
      "29 : 10\n",
      "4 : 16\n",
      "46 : 12\n",
      "84 : 12\n",
      "70 : 12\n",
      "59 : 15\n",
      "76 : 13\n",
      "80 : 14\n",
      "21 : 12\n",
      "73 : 7\n",
      "83 : 12\n",
      "38 : 11\n",
      "80 : 14\n",
      "28 : 11\n",
      "3 : 14\n",
      "81 : 11\n",
      "77 : 8\n",
      "59 : 15\n",
      "29 : 10\n",
      "19 : 16\n",
      "20 : 13\n",
      "47 : 12\n",
      "45 : 15\n",
      "53 : 13\n",
      "76 : 13\n",
      "76 : 13\n",
      "29 : 10\n",
      "40 : 16\n",
      "80 : 14\n",
      "76 : 13\n",
      "14 : 5\n",
      "7 : 7\n",
      "27 : 10\n",
      "89 : 9\n",
      "75 : 13\n",
      "88 : 7\n",
      "40 : 16\n",
      "0 : 8\n",
      "11 : 5\n",
      "41 : 13\n",
      "28 : 11\n",
      "67 : 6\n",
      "72 : 7\n",
      "69 : 13\n",
      "7 : 7\n",
      "72 : 7\n",
      "67 : 6\n",
      "92 : 9\n",
      "29 : 10\n",
      "31 : 9\n",
      "15 : 9\n",
      "17 : 9\n",
      "88 : 7\n",
      "78 : 8\n",
      "88 : 7\n",
      "52 : 13\n",
      "93 : 10\n",
      "4 : 16\n",
      "95 : 9\n",
      "52 : 13\n",
      "97 : 11\n",
      "63 : 3\n",
      "2 : 5\n",
      "28 : 11\n",
      "80 : 14\n",
      "89 : 9\n",
      "9 : 13\n",
      "60 : 11\n",
      "58 : 13\n",
      "42 : 5\n",
      "3 : 14\n",
      "82 : 11\n",
      "33 : 14\n",
      "77 : 8\n",
      "33 : 14\n",
      "53 : 13\n",
      "23 : 12\n",
      "96 : 11\n",
      "92 : 9\n",
      "13 : 8\n",
      "50 : 10\n",
      "68 : 9\n",
      "30 : 13\n",
      "1 : 7\n",
      "63 : 3\n",
      "99 : 13\n",
      "97 : 11\n",
      "65 : 7\n",
      "83 : 12\n",
      "82 : 11\n",
      "9 : 13\n",
      "84 : 12\n",
      "52 : 13\n",
      "96 : 11\n",
      "93 : 10\n",
      "58 : 13\n",
      "37 : 11\n",
      "65 : 7\n",
      "75 : 13\n",
      "81 : 11\n",
      "21 : 12\n",
      "57 : 4\n",
      "36 : 13\n",
      "70 : 12\n",
      "78 : 8\n",
      "62 : 10\n",
      "91 : 7\n",
      "43 : 17\n",
      "55 : 11\n",
      "33 : 14\n",
      "18 : 13\n",
      "13 : 8\n",
      "49 : 12\n",
      "22 : 7\n",
      "62 : 10\n",
      "33 : 14\n",
      "64 : 12\n",
      "65 : 7\n",
      "57 : 4\n",
      "47 : 12\n",
      "74 : 9\n",
      "34 : 11\n",
      "77 : 8\n",
      "81 : 11\n",
      "36 : 13\n",
      "59 : 15\n",
      "45 : 15\n",
      "68 : 9\n",
      "84 : 12\n",
      "47 : 12\n",
      "88 : 7\n",
      "99 : 13\n",
      "100 : 14\n",
      "59 : 15\n",
      "18 : 13\n",
      "32 : 8\n",
      "28 : 11\n",
      "80 : 14\n",
      "85 : 9\n",
      "61 : 13\n",
      "6 : 7\n",
      "52 : 13\n",
      "34 : 11\n",
      "69 : 13\n",
      "41 : 13\n",
      "39 : 10\n",
      "59 : 15\n",
      "87 : 17\n",
      "100 : 14\n",
      "18 : 13\n",
      "50 : 10\n",
      "32 : 8\n",
      "48 : 9\n",
      "82 : 11\n",
      "28 : 11\n",
      "81 : 11\n",
      "70 : 12\n",
      "11 : 5\n",
      "38 : 11\n",
      "36 : 13\n",
      "10 : 8\n",
      "16 : 9\n",
      "83 : 12\n",
      "55 : 11\n",
      "95 : 9\n",
      "30 : 13\n",
      "4 : 16\n",
      "20 : 13\n",
      "87 : 17\n",
      "40 : 16\n",
      "47 : 12\n",
      "27 : 10\n",
      "73 : 7\n",
      "42 : 5\n",
      "81 : 11\n",
      "16 : 9\n",
      "78 : 8\n",
      "100 : 14\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "x = [random.randint(0,100)for i in range(1000)]\n",
    "print(x)\n",
    "for i in x:\n",
    "    print(i,':',x.count(i))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "16."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "17."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "input your nameXI\n"
     ]
    }
   ],
   "source": [
    "d = {'LI':'1','XI':'2','GUA':3}\n",
    "a = input('input your name')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n"
     ]
    }
   ],
   "source": [
    "print(d.get(a,'您输入的键不存在'))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "18."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[37, 22, 20, 5, 46, 75, 69, 0, 56, 71, 20, 73, 29, 65, 76, 89, 52, 21, 71, 82]"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import random\n",
    "s = [random.randint(0,100)for i in range(20)]\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0, 5, 20, 22, 37, 46, 56, 69, 71, 75, 89, 82, 76, 73, 71, 65, 52, 29, 21, 20]\n"
     ]
    }
   ],
   "source": [
    "a = sorted(s[:10])\n",
    "b = sorted(s[10:],reverse = True)\n",
    "x = a+b\n",
    "print(x)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "165px"
   },
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
